<!DOCTYPE html>
<html lang="en" class="app">
<head>
<meta charset="utf-8" />
<title>Notebook | Web Application</title>
<meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link rel="stylesheet" href="${base}/css/bootstrap.4.0.css" type="text/css" />
<link rel="stylesheet" href="${base}/css/app.v2.css" type="text/css" />
<link rel="stylesheet" href="${base}/css/bootstrap-table.css" type="text/css" />
<style type="text/css">
  html,body{
    background-color: #ffffff;
  }
</style>
</head>

<body>
<section class="panel-default">
  <div class="panel-body">
    <form class="bs-example form-horizontal" action="UpdateOrAddEntity" method="post">
        <input type="hidden" id="flag" name="flag" value="${baseUser.userid}" />
        <div class="form-group">
            <label class="col-xs-3 control-label col-sm-offset-2" style="text-align:right;"><span class="redFlag">*</span>登录名:</label>
            <div class="col-xs-8 col-sm-offset-2">
                <input type="text"  class="form-control" <#if baseUser.userid?? >readonly</#if> id="userid" name="userid" value="${baseUser.userid}" placeholder="请输入登录名">
            </div>
        </div>
      <div class="form-group">
        <label class="col-xs-3 control-label col-sm-offset-2" style="text-align:right;"><span class="redFlag">*</span>姓名:</label>
        <div class="col-xs-8 col-sm-offset-2">
          <input type="text" class="form-control" id="userName" name="userName" value="${baseUser.username}" placeholder="请输入姓名">
        </div>
      </div>
        <div class="form-group">
            <label class="col-xs-3 control-label col-sm-offset-2" style="text-align:right;"><span class="redFlag"></span>头像:</label>
            <div class="col-xs-8 col-sm-offset-2">
                <div class="famous-upload-pic">
                    <#if baseUser.headlogo?if_exists  >
                        <img src="${baseUser.headlogo}"  class="upload-avatar" id="upload-avatar-s">
                        <#else>
                        <img src="${s.base}/image/head_defalut.png"  class="upload-avatar" id="upload-avatar">
                    </#if>
                    <input type="file" name="myfiles" class="upload" id="myFile" onchange="ajaxFileUploads('myFile','headLogo')">
                    <input type="hidden" id="headLogo" <#if baseUser.headlogo?if_exists  > value="${baseUser.headlogo}"  <#else> value="/image/head_defalut.png" </#if> />
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label col-sm-offset-2" style="text-align:right;"><span class="redFlag">*</span>密码:</label>
            <div class="col-xs-8 col-sm-offset-2">
                <input type="password" class="form-control" id="password" name="password" value="${baseUser.userpassword}" placeholder="请输入密码">
            </div>
        </div>

        <div class="form-group">
            <label class="col-xs-3 control-label col-sm-offset-2" style="text-align:right;"><span class="redFlag">*</span>组织:</label>
            <div class="col-xs-8 col-sm-offset-2">
                <select class="form-control" id="departid" style="height: 34px;" name="departid" value="${baseUser.departid}">
                    <option value="">--请选择--</option>
                    <#list baseDepartsList as baseDepart>
                        <option <#if baseUser.departid == baseDepart.departid >selected</#if> value="${baseDepart.departid}">${baseDepart.departname}</option>
                    </#list>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-xs-3 control-label col-sm-offset-2" style="text-align:right;"><span class="redFlag">*</span>手机:</label>
            <div class="col-xs-8 col-sm-offset-2">
                <input type="text" class="form-control" id="phone" name="phone" value="${baseUser.phone}" placeholder="请输入手机">
            </div>
        </div>

        <div class="form-group">
            <label class="col-xs-3 control-label col-sm-offset-2" style="text-align:right;"><span class="redFlag">*</span>邮箱:</label>
            <div class="col-xs-8 col-sm-offset-2">
                <input type="text" class="form-control" id="mail" name="mail" value="${baseUser.mail}" placeholder="请输入邮箱">
            </div>
        </div>

        <div class="form-group">
            <label class="col-xs-3 control-label col-sm-offset-2" style="text-align:right;">备注:</label>
            <div class="col-xs-8 col-sm-offset-2">
                <input type="text" class="form-control" id="remark" name="remark" value="${baseUser.remark}" placeholder="请输入备注">
            </div>
        </div>

      <div class="line line-dashed line-lg pull-in"></div>
      <div class="form-group" >
        <div class="col-sm-12 col-sm-offset-2" style="text-align: center;">
          <button type="button" onclick="parentLayerClose()" class="btn btn-default">取消</button>
          &nbsp;&nbsp;
          <button type="button" onclick="updateOrAdd()" class="btn btn-primary">确定</button>
        </div>

      </div>

    </form>
  </div>
</section>
<script src="${base}/js/jquery-3.2.0.min.js"></script>
<script src="${base}/js/layer/layer.js"></script>
<script src="${base}/js/layer/commont.js"></script>
<script src="${base}/js/bootstrap.4.0.js"></script>
<script src="${base}/js/bootstrap-table.js"></script>
<script src="${base}/js/bootstrap-table-zh-CN.js"></script>
<script type="text/javascript" src="${base}/js/ajaxfileupload.js"></script>

<script type="text/javascript">
    function ajaxFileUploads(){
        //开始上传文件时显示一个图片,文件上传完成将图片隐藏
        //$("#loading").ajaxStart(function(){$(this).show();}).ajaxComplete(function(){$(this).hide();});
        //执行上传文件操作的函数
        $.ajaxFileUpload({
            //处理文件上传操作的服务器端地址(可以传参数,已亲测可用)
            url:'/file/fileUpload?uname=123',
            secureuri:false,                           //是否启用安全提交,默认为false
            fileElementId:'myFile',               //文件选择框的id属性
            dataType:'text',                           //服务器返回的格式,可以是json或xml等
            success:function(data, status){            //服务器响应成功时的处理函数
                data = data.replace(/<pre.*?>/g, '');  //ajaxFileUpload会对服务器响应回来的text内容加上<pre style="....">text</pre>前后缀
                data = data.replace(/<PRE.*?>/g, '');
                data = data.replace("<PRE>", '');
                data = data.replace("</PRE>", '');
                data = data.replace("<pre>", '');
                data = data.replace("</pre>", '');     //本例中设定上传文件完毕后,服务端会返回给前台[0`filepath]
                if(data.substring(0, 1) == 0){         //0表示上传成功(后跟上传后的文件路径),1表示失败(后跟失败描述)
                    $("#upload-avatar").attr("src", data.substring(2));
                    $("#upload-avatar-s").attr("src", data.substring(2));
                    $("#headLogo").val(data.substring(2));
                    $('#result').html("图片上传成功<br/>");
                }else{
                    $('#result').html('图片上传失败，请重试！！');
                }
            },
            error:function(data, status, e){ //服务器响应失败时的处理函数
                $('#result').html('图片上传失败，请重试！！');
            }
        });
    }
</script>

<script type="text/javascript">
/**
  * 添加或修改
  */
 function updateOrAdd() {
     var userid=$("#userid").val();
     var headLogo=$("#headLogo").val();

     if (userid==null || ""==userid){
         layer.alert("请输入登录名！");
         return false;
     }
    var reg=/^[a-z A-Z_0-9]{5,12}$/;
    if (!reg.exec(userid)) {
        layer.alert("请输入5-12位字符串！");
        return false;
    }
     var userName=$("#userName").val();
     if (userName==null || ""==userName){
         layer.alert("请输入用户名！");
         return false;
     }
     var password=$("#password").val();
     if (password==null || ""==password){
         layer.alert("请输入密码！");
         return false;
     }
    if (!reg.exec(password)) {
        layer.alert("请输入5-12位字符串！");
        return false;
    }
     var departid=$("#departid").find("option:selected").val();
     if (departid==null || ""==departid){
         layer.alert("请选择组织！");
         return false;
     }
     var flag=$("#flag").val();
     if (flag==null || ""==flag){
         flag="add";
     }

    var phone=$("#phone").val();
    var mail=$("#mail").val();
    var remark=$("#remark").val();

     $.ajax({
         type: "POST",
         url: "/baseUser/UpdateOrAddEntity",
         data: {"userid":userid,"username":userName,"userpassword":password,"departid":departid,"headLogo":headLogo,"flag":flag,"phone":phone,"mail":mail,"remark":remark},
         success: function(result){
             parentLayerClose();
             if(1==result.returnInfo.state){
                 parent.showLayerAlert("操作成功");
             }else{
                 parent.showLayerAlert(result.returnInfo.errorMsg);
             }
         },
         error: function(result){
             parent.showLayerAlert(result);
         }
     });
 }
</script>
</body>
</html>
